//微信--微信设置
import React from 'react'
import PageTitle from '../../component/set/PageTitle'
import IconFont from '../../component/logo'
import '../Set/css/storeShowSet.css'
import '../Set/css/StoreInfo.css'
import './css/wei-xin-set.css'
import axios from '../../utils/http'
import {Form, Input, Button, message} from "antd";
const layout = {
    labelCol: { span: 8 },
    wrapperCol: { span: 14 },
};

class WeiXinSet extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            url:'',
            token:'',
            appId:'',
            AppSecret:'',
            content:''
        };
    }
    componentDidMount() {
      axios.get('/mm-wechat/options/queryWechatOptions').then(data=>{

          this.setState({
              url:data.data.data[0].url,
              token:data.data.data[0].token,
              appId:data.data.data[0].appld,
              AppSecret:data.data.data[0].appsecret,
              content:data.data.data[0].reply
          })
      })

    }

    urlMethod=(e)=>{
        console.log(12312)
        this.setState({
            url:e.target.value
        })
    }
    tokenMethod=(e)=>{
        this.setState({
            token:e.target.value
        })
    }
    appidMethod=(e)=>{
         this.setState({
             appId:e.target.value
        })
    }
    appSecretMethod=(e)=>{
        this.setState({
            AppSecret:e.target.value
        })
    }
    contentMethod=(e)=>{
        this.setState({
            content:e.target.value
        })
    }
    changeSure=()=>{
        axios.post('/mm-wechat/options/updateWechatOptions',{
            appld:this.state.appId,
            appsecret: this.state.AppSecret,
            reply: this.state.content,
            token: this.state.token,
            url: this.state.url,
            wechatSetId: 0
        }).then(data=>{
           if(data.data.code==200){
               message.success('修改成功')
               this.setState({
                   url:data.data.data.url,
                   token:data.data.data.token,
                   appId:data.data.data.appld,
                   AppSecret:data.data.data.appsecret,
                   content:data.data.data.reply
               })
           }else{
               message.error('修改失败')
           }

        })
    }
    render() {

        return (
            <div className='WeiXinSet'>
                <PageTitle title='微信设置' icon={<IconFont type='icon-weixinshezhi'></IconFont>}></PageTitle>
                <div className='wei_xin_set store_show_set storeInfo'>
                    <Form {...layout} name="infoOne">
                        <Form.Item
                            label="URL"
                            name="storeName"

                            rules={[{ required: true, message: "请输入URL" }]}
                        >
                            <Input className="info-border" key={this.state.url} defaultValue={this.state.url} onBlur={this.urlMethod} placeholder='请输入URL'></Input>
                        </Form.Item>
                        <Form.Item
                            label="Token"
                            name="storeTitle"
                            rules={[{ required: true, message: "请输入Token" }]}
                        >
                            <Input className="info-border" onBlur={this.tokenMethod} key={this.state.token} defaultValue={this.state.token}></Input>
                        </Form.Item>
                        <Form.Item
                            label="AppId"
                            name="storeDescribe"
                            rules={[{ required: true, message: "请填写AppId" }]}
                        >
                            <Input  defaultValue={this.state.appId}
                                className="info-border"
                                    key={this.state.appId}
                                    onBlur={this.appidMethod}
                            ></Input>
                        </Form.Item>
                        <Form.Item
                            label="AppSecret"
                            name="storeKeyWorlds"
                            rules={[{ required: true, message: "请填写AppSecret" }]}
                        >
                            <Input className="info-border" onBlur={this.appSecretMethod} key={this.state.AppSecret}  defaultValue={this.state.AppSecret}></Input>
                        </Form.Item>
                        <div className="formTwo formTwoBorder">
                            <Form.Item
                                label="关注回复内容"
                                name="closeStoreResin"
                                rules={[{ required: true, message: "请填写关注回复内容" }]}
                            >
                                <Input.TextArea
                                    className="info-border"
                                    maxLength={100}
                                    defaultValue={this.state.content}
                                    key={this.state.content}
                                    onBlur={this.contentMethod}
                                ></Input.TextArea>
                            </Form.Item>
                        </div>
                        <div className="btn">
                            <Button onClick={this.changeSure}>确定</Button>
                        </div>
                    </Form>
                </div>
            </div>
        );
    }
}

export default WeiXinSet